//
//  UIImageView+Extension.swift
//  个人微博
//
//  Created by guo3920591 on 16/4/17.
//  Copyright © 2016年 guo3920591. All rights reserved.
//

import UIKit

import SDWebImage

extension UIImageView {
    /// 通过图片名创建UIimageview
    /// - parameter imageName: 图像名
   
    convenience init(imageName: String){
        
        self.init(image:UIImage(named: imageName))
        
        
    }
    
    func xl_setImageUrl(urlString: String?,size: CGSize = CGSizeZero,
        isCorner: Bool = false,
        backColor: UIColor? = UIColor.whiteColor(),placeHoder: String?){
        
        //占位图
        var palacehoderImage: UIImage?
        
        if placeHoder != nil {
            
            palacehoderImage = UIImage(named: placeHoder!)
        }
        
        guard let uirString = urlString,let url = NSURL(string: uirString) else{
            
            image = palacehoderImage
            
            return
        }
        
            if size == CGSizeZero {
      sd_setImageWithURL(url, placeholderImage: palacehoderImage)
                
                return
            }
        sd_setImageWithURL(url, placeholderImage: palacehoderImage) { (image, _, _, _) -> Void in
            
            guard let image = image else{
                
                return
            }
            
            image.cz_asyncDrawImage(size, isCorner: isCorner, backColor: backColor, finished: { (image) -> () in
                
                self.image = image
                
            })
            
            
            
            
        }
        
        
    }
    
    
    
}
